import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import * as echarts from 'echarts'
import Vant from 'vant';
import 'vant/lib/index.css';
import GoodsList from "./components/GoodsList";


//处理跨域
// 引用axios，并设置基础URL为后端服务api地址
var axios = require('axios')
axios.defaults.baseURL = 'http://localhost:10086'  //此处是https协议如果不是改成http

//axios.defaults.withCredentials = true    //全局设置axios允许携带cookie进行访问   

// 将API方法绑定到全局
Vue.prototype.$axios = axios

Vue.config.productionTip = false

Vue.use(ElementUI);
Vue.use(Vant);
Vue.prototype.$echarts = echarts
Vue.component('googs-list',GoodsList)

// 添加请求拦截器，在请求头部加token
axios.interceptors.request.use(
  config => {
    if (localStorage.getItem('token')) {
      config.headers.token = localStorage.getItem('token');
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'

})
